import { Window } from "../../../../component/window/Window";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { PetCpnRewardUtil } from "./info/PetCpnRewardUtil";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetCpnInsureWindow
    
    export  class PetCpnInsureWindow extends Window
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(270, 225);
            this.titleHeight = 28;
            return;
        }

        public set isInsurance(arg1: Boolean)
        {
            this._isInsurance = arg1;
            this._insureBtn.visible = !arg1;
            if (this._insureIcon) 
            {
                this._insureIcon.visible = arg1;
            }
            return;
        }

        public updateReward(arg1: Array<any>): void
        {
            var loc1=null;
            if (arg1) 
            {
                loc1 = PetCpnRewardUtil.getStrByRewardArray(arg1);
                loc1 = loc1.substring(0, loc1.indexOf("×"));
                this._rewardTxt.htmlText = loc1;
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            _titleSprite.visible = false;
            _windowBg = ResouceConst.getScaleBitmap(ImagesConst.ToolTipBg);
            _windowBg.width = 275;
            _windowBg.height = 265;
            $addChildAt(_windowBg, 0);
            ObjCreate.createGTextField(Language.getString(54793), 7, 40, 70, 20, this, GlobalStyle.textFormat6);
            this._goldTxt = ObjCreate.createGTextField("5", 67, 40, 70, 20, this);
            ObjCreate.createBitmap(ImagesConst.Yuanbao, 80, 40, this);
            ObjCreate.createGTextField(Language.getString(54794), 7, 60, 70, 20, this, GlobalStyle.textFormat6);
            this._rewardTxt = ObjCreate.createGTextField("", 67, 60, 70, 20, this);
            this._rewardTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(10, 88, 230, 1, this, ImagesConst.SeptalLine);
            ObjCreate.createGTextField(Language.getString(54796), 7, 100, 70, 20, this, GlobalStyle.textFormat6);
            this._descTxt = ObjCreate.createGTextField("", 67, 100, 190, 20, this);
            this._descTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTxt.wordWrap = true;
            this._descTxt.multiline = true;
            this._descTxt.htmlText = Language.getString(54797);
            ObjCreate.createBg(10, 175, 230, 1, this, ImagesConst.SeptalLine);
            ObjCreate.createGTextField(Language.getString(54798), 7, 188, 200, 20, this);
            ObjCreate.createGTextField(Language.getString(54799), 7, 208, 200, 20, this, GlobalStyle.textFormatGreen);
            this._nameTxt = ObjCreate.createGTextField("", 43, 208, 200, 20, this, GlobalStyle.textFormatGreen);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.htmlText = "";
            this._insureBtn = ObjCreate.createGButton(Language.getString(54800), 98, 230, 70, 29, this, "ArenaRedBtn");
            this._insureBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onInsureBtnClickHandler);
            LoaderHelp.addResCallBack(ResFileConst.PetCpn, this.onLoadedHandler);
            return;
        }

        protected /* override */ updateBtnSize(): void
        {
            super.updateBtnSize();
            _closeBtn.x = this.width - _closeBtn.width;
            _closeBtn.y = 5;
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            ObjCreate.createBitmap(ImagesConst.PetInsureTitle, 96, 12, this);
            this._insureIcon = ObjCreate.createBitmap(ImagesConst.PetInsureIcon, 150, 182, this);
            return;
        }

        /* internal  */onInsureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnInsure));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._nameTxt.htmlText = Cache.instance.role.entityInfo.name;
            return;
        }

        /* internal */ /* var */_goldTxt: GTextFiled;

        /* internal */ /* var */_rewardTxt: GTextFiled;

        /* internal */ /* var */_descTxt: GTextFiled;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_insureBtn: GButton;

        /* internal */ /* var */_insureIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isInsurance: Boolean;
    }
